package com.zr.aop;

import com.zr.utils.TokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Arrays;

@Aspect
@Component
@Slf4j
public class LogAop {

    @Resource
    private TokenUtil tokenUtil;

    @Around("execution(* com.zr.service..*.*(..))")
    public Object methodAop(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        String className = proceedingJoinPoint.getTarget().getClass().getName();
        String methodName = proceedingJoinPoint.getSignature().getName();
        Object[] args = proceedingJoinPoint.getArgs();
        String currentUserId = null;
        try{
            currentUserId = tokenUtil.currentUserId();
        }catch (Exception e){
            log.warn(e.getMessage());
        }
        log.info("操作人:" + currentUserId + " 类名:" + className + " 方法:" + methodName + " 参数:" + Arrays.toString(args));
        return proceedingJoinPoint.proceed();
    }

}